<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "config/config.php";
include "auth.php";
include "DBManager.php";

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

/* 判断相应的文件夹是否存在 */

$path = explode("/", $dbPath);

if (!is_dir($path[0])) {
    mkdir($path[0]);
}

/* 如果数据库不存在，创建数据库 */

if (!is_file($dbPath)) {

    $db = new DBManager("sqlite:" . $dbPath);
    $db->createTables();

    $str = "Refresh:3,Url=" . $homepage;
    header($str);

    echo <<<BBB
        数据库创建成功！
        <br />
        3秒后自动跳转到主页！
    BBB;

    exit();

}

// -----------------------------------------------------------------------------

// 设置时区
date_default_timezone_set($region);

$today = new DateTime("today");
$todayStr = $today->format("Ymd");

$tomorrow = $today->add(new DateInterval("P1D")); // $today 的值这里会改变
$tomorrowStr = $tomorrow->format("Ymd");

// -----------------------------------------------------------------------------
?>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Todo</title>
    <link rel="stylesheet" href="resources/bootstrap-5.2.0-beta1-dist/css/bootstrap.min.css">
    <base target="_self">
</head>
<body>

<!-- ----------------------------------------------------------------------- -->

<script src="resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>
<script src="resources/jQuery/jquery-3.5.1.js"></script>
<?php include "globalNavbar.php"; ?>

<!-- ----------------------------------------------------------------------- -->

<div class="container container-fluid mt-3 mb-5">

    <!-- 导航栏 开始 -->
    <div class="mt-3">
        <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a class="text-decoration-none" href="<?php echo $homepage; ?>">首页</a>
                </li>
            </ol>
        </nav>
    </div>
    <!-- 导航栏 结束 -->

    <div class="list-group mt-3">

        <a href="viewByDate.php?date=today" class="list-group-item list-group-item-action">
            <?php echo $linkTitleToday; ?>
        </a>

        <a href="viewByDate.php?date=tomorrow" class="list-group-item list-group-item-action">
            <?php echo $linkTitleTomorrow; ?>
        </a>

        <a href="tasksInFuture/index.php" class="list-group-item list-group-item-action">
            <?php echo $linkTitleFuture; ?>
        </a>

        <a href="tasksInSpecific/index.php" class="list-group-item list-group-item-action">
            <?php echo $linkTitleSpecific; ?>
        </a>

    </div>

   <div class="list-group mt-3">

        <a href="repeat/specify.php" class="list-group-item list-group-item-action">
            <?php echo $linkTitleEditRepeatTasks; ?>
        </a>

        <a href="repeat/view.php" class="list-group-item list-group-item-action">
            <?php echo $linkTitleViewRepeatTasks; ?>
        </a>

    </div>

    <div class="list-group mt-3">
        <a href="storageBox/index.php" class="list-group-item list-group-item-action">待办事务收纳箱</a>
        <a href="shoppingList/index.php" class="list-group-item list-group-item-action">购物清单</a>
        <a href="summariesAndPlans/index.php" class="list-group-item list-group-item-action">总结与规划</a>
        <a href="goalsManager/index.php" class="list-group-item list-group-item-action">目标与行动计划</a>
    </div>

    <div class="list-group mt-3 mb-3">
        <a href="search/index.php" class="list-group-item list-group-item-action">搜索</a>
        <a href="recreateDatabase/index.php" class="list-group-item list-group-item-action">重置数据库</a>
        <a href="about/index.php" class="list-group-item list-group-item-action">关于</a>
    </div>

</div>

<!----------------------------------------------------------------------------->

<script src="resources/jQuery/jquery-3.5.1.js"></script>
<script src="resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>

<!----------------------------------------------------------------------------->

</body>
</html>
